package com.android.bookgarden.ui;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.bookgarden.R;
import com.android.bookgarden.base.BaseActivity;

import butterknife.BindView;

/**
 * Create by zouqh
 * on 2018/11/28
 **/
public class FundPassWordActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.close)
    ImageView close;
    @BindView(R.id.title_text)
    TextView titleText;
    @BindView(R.id.ritgh_icon)
    ImageView ritghIcon;
    @BindView(R.id.ritgh_text)
    TextView ritghText;
    @BindView(R.id.telPhone)
    EditText telPhone;
    @BindView(R.id.sendCode)
    TextView sendCode;
    @BindView(R.id.smsCode)
    EditText smsCode;
    @BindView(R.id.passWord)
    EditText passWord;
    @BindView(R.id.lookPass)
    CheckBox lookPass;
    @BindView(R.id.loinBut)
    TextView loinBut;

    private int recLen = 61;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_fund_passwrod;
    }

    @Override
    protected void initView() {
        close.setOnClickListener(this);
        sendCode.setOnClickListener(this);

        lookPass.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                // TODO Auto-generated method stub
                if (isChecked) {
                    // 设置成明文
                    // This transformation method causes any carriage return

                    passWord
                            .setTransformationMethod(HideReturnsTransformationMethod
                                    .getInstance());
                } else {
                    // 设置成密文
                    //
                    passWord
                            .setTransformationMethod(PasswordTransformationMethod
                                    .getInstance());
                }
            }
        });

    }

    @Override
    public void onRequestPermissions(String str, boolean z) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.close:
                finish();

                break;
        }

    }


    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 1:
                    recLen--;
                    sendCode.setText("已发送(" + recLen + "秒)");
                    if (recLen > 0) {
                        telPhone.setEnabled(false);
//                        telPhone.setClearIconVisible(false);
                        sendCode.setClickable(false);
                        Message message = handler.obtainMessage(1);
                        handler.sendMessageDelayed(message, 1000); // send message
                    } else {
                        sendCode.setText("重新获取");
                        telPhone.setEnabled(true);
                        sendCode.setClickable(true);
                        recLen = 61;
                    }
                    break;
            }
        }
    };


}
